package models

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type JackPotPoll struct {
	ID           string    `gorm:"primarykey" json:"id" `
	TotalAmount  float64   `json:"totalAmount" gorm:"type:decimal(10,2);default:0.00"`
	GameResultId string    `gorm:"index;type:varchar(36);not null;unique" json:"gameResultId"`
	GameCode     string    `json:"gameCode" gorm:"type:varchar(36);not null;unique"`
	OddsValue    float64   `json:"oddsValue" gorm:"type:decimal(10,2);default:0.00"`
	CreatedAt    time.Time `json:"createdAt"`
	UpdatedAt    time.Time `json:"updatedAt"`
}

func (JackPotPoll) TableName() string {
	return "jackpot_poll"
}

func (j *JackPotPoll) BeforeCreate(tx *gorm.DB) (err error) {
	j.ID = uuid.NewString()
	j.CreatedAt = time.Now()
	j.UpdatedAt = time.Now()
	return
}

func (j *JackPotPoll) BeforeUpdate(tx *gorm.DB) (err error) {
	j.UpdatedAt = time.Now()
	return
}
